package leader.action;

import java.util.ArrayList;
import java.util.List;

import leader.service.DirectPatentService;
import leader.service.DirectProjectService;
import leader.service.DirectTeacherService;
import leader.tool.JTableDefine;
import teacher.bean.Patent;
import teacher.bean.Project;
import teacher.bean.Teacher;
import tools.StringDate;

import com.opensymphony.xwork2.ActionContext;

public class DirectProjectPrintAction {
	private String datedown;
	private String dateup;
	private String proName;
	private int flag;
	public String getDatedown() {
		return datedown;
	}

	public void setDatedown(String datedown) {
		this.datedown = datedown;
	}

	public String getDateup() {
		return dateup;
	}

	public void setDateup(String dateup) {
		this.dateup = dateup;
	}
	public String getProName() {
		return proName;
	}

	public void setProName(String proName) {
		this.proName = proName;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public String execute() {
		Teacher lea=(Teacher) ActionContext.getContext().getSession().get("leader");
		DirectTeacherService DT = new DirectTeacherService();
		List<Project> lists = new ArrayList<Project>();
		DirectProjectService DP = new DirectProjectService();
		System.out.println("========="+flag);
		if(0 == flag) {
			lists = DP.selectAllDirectProject(lea);
		}
		if(1 == flag) {
			StringDate date = new StringDate();
			lists = DP.selectDirectProjectByTime(date.StringToDate(datedown),date.StringToDate(dateup), lea);
		}
		if(2 == flag) {
			System.out.println("==========="+proName);
			lists = DP.selectProjectLikeName(proName, lea);
		}
		if(3 == flag) {
			Project pro = new Project();
			pro.setState(0);
			lists = DP.selectDirectProjectByState(lea, pro);
		}
		System.out.println(lists.size());
		String[][] columnNames = new String[lists.size()+1][7];		
		columnNames[0] = new String[]{"编号","名称","负责人","项目级别","项目类型","到账经费","开发周期"};
		for(int i=1;i<lists.size()+1;i++) {
			Project project = lists.get(i-1);
			columnNames[i][0] = String.valueOf(i);
			columnNames[i][1] = project.getName();
			Teacher tea = new Teacher();
			tea.setTeaId(project.getTeaId());			
			columnNames[i][2] = DT.selectTeacherById(tea).getName();
			columnNames[i][3] = String.valueOf(project.getLevel());
			columnNames[i][4] = String.valueOf(project.getKind());
			columnNames[i][5] = String.valueOf(project.getArriveFunds());
			StringDate date = new StringDate();
			columnNames[i][6] = date.DateToString(project.getBeginDate())+"至"+date.DateToString(project.getFinishDate());
		}
		int[] px = new int[]{40,120,50,50,60,60,145};
		JTableDefine d = new JTableDefine();
		d.printTable(columnNames,px);
		System.out.println("============================");
		return "success";
	}
}
